package pt.ua.helpdesk.client;

import java.util.ArrayList;

import com.google.gwt.core.client.GWT;
import com.google.gwt.user.client.rpc.RemoteService;
import com.google.gwt.user.client.rpc.ServiceDefTarget;

public interface ServiceTickets extends RemoteService {
	/**
	 * Add a ticket
	 * 
	 * @param title Title of the ticket
	 * @param question Question placed by the user
	 * @param status Status of the ticket (1 - Pending; 2 - Solving; 3 - Solved)
	 * @param active Indicates whether the ticket is active or not (1 - Active; 0 - Inactive)
	 * @param idPerson ID of the author of the ticket 
	 * @return True in case of ticket successfully added, False otherwise
	 */
	Boolean addTicket(String title, String question, Integer status, Integer active, Integer idPerson);
	/**
	 * Removes a ticket
	 * 
	 * @param idTicket ID of the ticket to be removed
	 * @return True in case of successful removal, False otherwise
	 */
	Boolean removeTicket(Integer idTicket);
	/**
	 * Retrieves a list of pending tickets of a given user
	 * 
	 * @return ArrayList of the pending tickets
	 */
	ArrayList getPendingTickets();
	/**
	 * Retrieves complete data on a ticket, including info and comments
	 *  
	 * @param ticketId ID of the ticket to be searched
	 * @return An ArrayList containing an ArrayList with the ticket info, and another with the ticket's comments
	 */
	ArrayList loadFullTicketData(Integer ticketId);
	
	/**
	 * Retrieves data necessary to assign a ticket to an assistant
	 *  
	 * @param ticketId ID of the ticket to be searched
	 * @return An ArrayList containing the ticket info and a list of active assistants 
	 */
	ArrayList loadDataForAssignment(Integer ticketId);
	
	/**
	 * Retrieves a list of tickets on charge of a specific user 
	 * 
	 * @param IDUser ID of the user
	 * @return ArrayList containing all active tickets of the assistant
	 */
	ArrayList getUserTickets(Integer IDUser);
	
	/**
	 * Retrieves a list of tickets on charge of a specific assistant 
	 * 
	 * @param IDAssistant ID of the assistant
	 * @return ArrayList containing all active tickets of the assistant
	 */
	ArrayList getAssisTickets(Integer IDAssis);
	
	/**
	 * Adds a comment to a ticket
	 * 
	 * @param authorId ID of the author of the ticket
	 * @param ticketId ID of the ticket
	 * @param text Text of the comment
	 * @return True in case of successful removal, False otherwise
	 */
	Boolean addComment(Integer authorId, Integer ticketId, String text) ;
	
	/**
	 * Assign a ticket to an assistant
	 * 
	 * @param assist target of the assignment
	 * @param admin administrator the did the assignment
	 * @param ticket ticket to be assigned
	 * @return True in case of successful assignment, False otherwise
	 */
	Boolean assignTicket(Integer assist, Integer admin, Integer ticket) ;
	
	Boolean setTicketAsSolved(Integer ticket) ;

	/**
	 * Utility class for simplifying access to the instance of async service.
	 */
	public static class Util {
		private static ServiceTicketsAsync instance;
		public static ServiceTicketsAsync getInstance(){
			if (instance == null) {
				instance = (ServiceTicketsAsync) GWT.create(ServiceTickets.class);
				ServiceDefTarget target = (ServiceDefTarget) instance;
				target.setServiceEntryPoint(GWT.getModuleBaseURL() + "ServiceTickets");
			}
			return instance;
		}
	}
}
